<script lang="ts" setup>
import { reactive, defineEmits } from "vue"
import { useRouter } from "vue-router"
import { addCoinService } from '../../../../api/coinService'
import { HttpStatusCode } from "axios"
import { ElMessage } from "element-plus"

const router = useRouter()
const emits = defineEmits(['increase', 'closeShow'])
let formLabelAlign = reactive<CoinService>({
  coin: 0,
  price: 0,
  remark: ''
})

const submitData = async () => {
  const res = await  addCoinService(formLabelAlign)
  if(res.statusCode === HttpStatusCode.Created) {
    ElMessage({
      message: '添加成功',
      type: 'success',
    })
    emits('increase', 1, '')
    emits('closeShow')
    // setTimeout(() => {
    //   router.go(0)
    // }, 1000)
  } else {
    ElMessage({
      message: '添加失败',
      type: 'error',
    })
  }
}
</script>

<template>
  <el-form
      label-position="top"
      label-width="100px"
      :model="formLabelAlign"
      style="max-width: 460px"
  >
    <el-form-item label="积分">
      <el-input-number v-model="formLabelAlign.coin">
      </el-input-number>
    </el-form-item>
    <el-form-item label="价格">
      <el-input-number v-model="formLabelAlign.price" :precision="1" :step="0.1">
      </el-input-number>
    </el-form-item>
    <el-form-item label="备注">
      <el-input :rows="2" type="textarea" v-model="formLabelAlign.remark" />
    </el-form-item>
  </el-form>
  <el-button type="primary" @click="submitData">提交</el-button>
</template>

<style lang="less" scoped>

</style>